package com.koron.system.schedule;

import com.koron.common.core.business.configsettings.utils.ConfigInfoTool;
import com.koron.system.staff.service.UnifyUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName UnifyOrgUserTask
 * @description
 * @Author zhouj
 * @Date 2021/7/9 11:56
 */
@Slf4j
@Component
@EnableScheduling   // .开启定时任务
public class UnifyOrgUserTask {

    @Autowired
    UnifyUserService unifyUserService;

    //定时任务调取
    //获取数据后  入库
    @Scheduled(cron = "0 0 2 * * ?")
    public void callInUpAllOrgNode() {
        String isNeedCallTask = ConfigInfoTool.getConfigByCode("system", "org").get("isNeedCallTask");
        if ("1".equals(isNeedCallTask)) {
            Map<String, String> map = new HashMap<>();
            //map.put("org", "yhszy");
            //map.put("root", "yhszy");
            try {
                //call org task
                // YJ TODO 2023/12/12 16:57
                unifyUserService.inUpAllOrgNode(map);
                log.info("同步统一组织成功");
            } catch (Exception e) {
                log.error("同步统一组织失败:{},{}", e.getMessage(),e);
            }

            try {
                //call staff task
                unifyUserService.inUpAllStaff(map);
                log.info("同步统一用户成功");
            } catch (Exception e) {
                log.error("同步统一用户失败:{},{}", e.getMessage(),e);
            }
        }
    }
}
